package com.gaff.emp.core;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Setter
@Getter
@ToString
public class R<V> {
    private static final long serialVersionUID = 1L;

    private int code;

    private String msg;

    private V data;

    public static R ok() {
        R r = new R();
        r.setCode(200);
        r.setMsg("!");
        return r;
    }

    public static <V> R ok(V data) {
        R r = new R();
        r.setCode(200);
        r.setMsg("!");
        r.setData(data);
        return r;
    }

    public static R error() {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), "未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(999);
        list.add(0);
        list.add(22);
        list.sort(Comparator.comparingInt(Integer::intValue));
        for (Integer i : list){
            System.out.println(i);
        }
    }
}
